package argo.hot100.stack;

import java.util.*;

public class MinStackOld {
    Map<Integer, Integer> tree = new TreeMap<>();
    Stack<Integer> stack = new Stack<>();

    public MinStackOld() {

    }

    public void push(int val) {
        stack.push(val);
        tree.put(val, tree.getOrDefault(val, 0) + 1);
    }

    public void pop() {
        Integer del = stack.pop();
        Integer delCnt = tree.get(del);
        if (delCnt > 1) {
            tree.put(del, delCnt - 1);
        } else {
            tree.remove(del);
        }
    }

    public int top() {
        return stack.peek();
    }

    public int getMin() {
        return tree.entrySet().iterator().next().getKey();
    }


    public static void main(String[] args) {
        Set<Integer> tree = new TreeSet<>();
        tree.add(3);
        tree.add(8);
        tree.add(1);
        tree.add(4);
        System.out.println(tree.iterator().next());
    }


}
